------------------------------------------------------- MX COBOL (mxc.lst) MX COBOL Version 3.0 - EN, Copyright (c) Vlastimil Cevela 1996, 2006 (20060528) D:\CeW\cobol\p\mx_b1.cb WHEN-COMPILED = 04/06/06 06:29:40 Registered user: 060529 Name, City, Country 0001 * Simple Calculator mx_b1.cb 0002 * 0003 working-storage section. 0004 1 Inp pic x(10) value ".". 0005 88 Work-end value " ". 0006 1 Ope pic x. 0007 88 Valid-operator value "+" "-" "*" "/". 0008 1 Int pic 9999. 0009 1 Sum pic 999 value 0. 0010 1 Sum-ed pic zz9. 0011 1 Rem pic 999. 0012 1 Rem-ed pic zz9. 0013 1 Err pic 9. 0014 * 0015 procedure division. 0016 perform Directions-for-use. 0017 * 0018 perform until Work-end 0019 accept Inp | 0005 0020 * 0021 if not Work-end | 0004 0022 unstring Inp | 0005 0023 delimited "+" or "-" or "*" or "/" or space | 0004 0024 into 0025 Int delimiter Ope | 0008 0026 Int | 0006 0027 perform Calcul | 0008 0028 else 0029 display "end of work" 0030 accept Inp 0031 end-if | 0004 0032 * 0033 end-perform. 0034 stop run. 0035 * 0036 Calcul. 0037 move 0 to Err Rem. | 0013 0011 0038 * 0039 if Ope = "+" | 0006 0040 add Int to Sum | 0008 0041# size error move 1 to Err. | 0009 0013 0042 * 0043 if Ope = "-" | 0006 0044 subtract Int from Sum | 0008 0045# size error move 1 to Err. | 0009 0013 0046 * 0047 if Ope = "*" | 0006 0048 multiply Sum by Int giving Sum | 0009 0008 0049# size error move 1 to Err. | 0009 0013 0050 * 0051 if Ope = "/" | 0006 0052 divide Sum by Int | 0009 0053 remainder Rem | 0008 0054# size error move 1 to Err. | 0011 0013 0055 * 0056 if not (Valid-operator) | 0007 0057# move 2 to Err. | 0013 0058 * 0059 if Err = 0 | 0013 0060 move Sum to Sum-ed | 0009 0061 display "= " Sum-ed | 0010 0062 if Rem > 0 | 0010 0011 0063 move Rem to Rem-ed | 0011 0064 display "remainder = " Rem-ed | 0012 0065 end-if else | 0012 0066 if Err = 1 | 0013 0067 display "Sum size error (max 999) or /0 !!!" 0068 display " " 0069 else 0070 display "invalid operator !!!" 0071# perform Directions-for-use. 0072 * 0073 Directions-for-use. 0074 display "Calculator - directions for use:". 0075 display 0076 " - input have to be operator and integer (max 3 digits) " 0077 "without space". 0078 display " - input is Enter only: program ends". 0079 display " - valid operators: +, -, *, /". 0080 display " ". DATA DIRECTORY: LV NAME OF ITEM ADDR TP LENG LINE REFERENCE 01 INP 0 AN 10 0004 0019 0022 0030 88 WORK-END 0005 0018 0021 01 OPE 16 AN 1 0006 0025 0039 0043 0047 0051 88 VALID-OPERATOR 0007 0056 01 INT 24 DI 4 0008 0025 0026 0040 0044 0048 0052 01 SUM 32 DI 3 0009 0040 0044 0048 0048 0052 0060 01 SUM-ED 40 NE 3 0010 0060 0061 01 REM 48 DI 3 0011 0037 0053 0062 0063 01 REM-ED 56 NE 3 0012 0063 0064 01 ERR 64 DI 1 0013 0037 0041 0045 0049 0054 0057 0059 0066 77 TALLY 72 BI 4 0000 77 NSTD-REELS 76 BI 2 0000 77 WHEN-COMPILED 80 AN 16 0000 ERROR LISTING: line 0003: warning 0002 level 0 (some division/section/paragraph header before WORKING-STORAGE missing - never mind) Errors: 0, warnings: 1 Turbo C Version 2.01 Copyright (c) 1987, 1988 Borland International d:\cew\cobol\p\mx_b1.c: Available memory 332324 Turbo C Version 2.01 Copyright (c) 1987, 1988 Borland International Turbo Link Version 2.0 Copyright (c) 1987, 1988 Borland International Available memory 413700 ------------------------------------------------------- main source C (.c) /* 0001 * Simple Calculator mx_b1.cb */ /* 0002 * */ /* 0003 working-storage section. */ /* 0004 1 Inp pic x(10) value ".". */ /* 0005 88 Work-end value " ". */ /* 0006 1 Ope pic x. */ /* 0007 88 Valid-operator value "+" "-" "*" "/". */ /* 0008 1 Int pic 9999. */ /* 0009 1 Sum pic 999 value 0. */ /* 0010 1 Sum-ed pic zz9. */ /* 0011 1 Rem pic 999. */ /* 0012 1 Rem-ed pic zz9. */ /* 0013 1 Err pic 9. */ /* 0014 * */ /* 0015 procedure division. */ #include "D:\CeW\cobol\p\mx_b1.d" #undef MXPE #define MXPE(x,y) goto x /* MX COBOL - Jan 08 2000, 16:35:41 */ _l0001: /* @@@ */ /* 0016 perform Directions-for-use. */ /* PERFORM */ if(!setjmp(ps[0])) {pk[0]=1; goto _l0002;} else pk[0]=0; /* . */ /* 0017 * */ /* 0018 perform until Work-end */ /* PERFORM */ for(;!(/* 0019 accept Inp */ ((icbacmp(W,10L," ",1L) == 0)));) { /* 1 */ /* ACCEPT */ /* 0020 * */ /* 0021 if not Work-end */ Y=(X=W)+10; while (X= 1000L)) goto __LER000; l3 = l1 - l0 * l2; if((l3 > -1000L) && (l3 < 1000L)) { /* 2 */ icbb4dim(l2 % 1000, W+32, 3, 128); icbb4dim(l3 % 1000, W+48, 3, 128); } /* 2 */ else __LER000: { /* 2 */ /* MOVE */ *(W+64)='1'; /* . */ } /* 2 */ } /* 1 */ /* 0055 * */ /* 0056 if not (Valid-operator) */ /* IF */ if (!((*(W+16) == '\x2b') || *(W+16) == '\x2d' || *(W+16) == '\x2a' || /* 0057 move 2 to Err. */ *(W+16) == '\x2f')) { /* 1 */ /* MOVE */ *(W+64)='2'; /* . */ } /* 1 */ /* 0058 * */ /* 0059 if Err = 0 */ /* IF */ if (/* 0060 move Sum to Sum-ed */ *(W+64) == '\x30') { /* 1 */ /* MOVE */ /* 0061 display "= " Sum-ed */ icbdine(W+32, 3, 0, W+40, "\0\377 ZZ9", 3); /* DISPLAY */ /* 0062 if Rem > 0 */ fprintf(J4,"= %.3s\n",W+40); /* IF */ if (/* 0063 move Rem to Rem-ed */ icbditos(W+48,3) > 0) { /* 2 */ /* MOVE */ /* 0064 display "remainder = " Rem-ed */ icbdine(W+48, 3, 0, W+56, "\0\377 ZZ9", 3); /* DISPLAY */ /* 0065 end-if else */ fprintf(J5,"remainder = %.3s\n",W+56); /* END-IF */ } /* 2 */ /* ELSE */ } /* 1 */ else { /* 1 */ /* 0066 if Err = 1 */ /* IF */ if (/* 0067 display "Sum size error (max 999) or /0 !!!" */ *(W+64) == '\x31') { /* 2 */ /* DISPLAY */ /* 0068 display " " */ fprintf(J6,"Sum size error (max 999) or /0 !!!\n"); /* DISPLAY */ /* 0069 else */ fprintf(J7," \n"); /* ELSE */ } /* 2 */ else { /* 2 */ /* 0070 display "invalid operator !!!" */ /* DISPLAY */ /* 0071 perform Directions-for-use. */ fprintf(J8,"invalid operator !!!\n"); /* PERFORM */ if(!setjmp(ps[0])) {pk[0]=1; goto _l0002;} else pk[0]=0; /* . */ } /* 2 */ } /* 1 */ /* 0072 * */ /* 0073 Directions-for-use. */ PK( 1); _l0002: /* DIRECTIONS-FOR-USE */ _f0002( argc, argv ); PK( 0); /*KONEC*/ /************ _() end **************/ ;} ------------------------------------------------------- 1st include C (.d) #include #include #include #include "c:\mxc\mxcsdtf.h" #include "c:\mxc\mxcicb.h" static void lojo(jmp_buf); static void lojo(lj1) jmp_buf lj1; {longjmp(lj1,1);} #define XERNF 0x01 extern jmp_buf ps[]; extern short pk[]; static unsigned char flag=0; /* 0x80 = ON SIZE ERROR, 0x40 = READY TRACE */ static short i0,i1; static short exprog=0; extern long xferr; static unsigned char W[32]={'.',' ',' ',' ',' ',' ',' ',' ',' ',' '}; static unsigned char W1[40]={'0','0','0'}; static unsigned char W2[8]={0,0,0,0,0,0}; static unsigned char W3[16]={'0','4','/','0','6','/','0','6','0','6',':', '2','9',':','4','0'}; static void _(int,char**); #define J1 stdout struct J3 {char j[3];}; #define J4 stdout #define J5 stdout #define J6 stdout #define J7 stdout #define J8 stdout #define J9 stdout #define J10 stdout #define J11 stdout #define J12 stdout #define J13 stdout #pragma warn -par static short _f0002(int argc, char **argv); #define PK(x) if(pk[x]) lojo(ps[x]) static jmp_buf ps[3]; static short pk[3]; extern double fabs(double); unsigned char icbdisac=0, icbbarvy = 0x07; #define STOPRUN static unsigned char *X,*Y,*Z,*Z1; /* pomocne ukazatele */ static long l0,l1,l2,l3; static double d0,d1,d2,d3; static unsigned char P[33]; /* pracovni pole pro vsechny */ static void _(int,char**); ANONYMUS() {exprog++; _(0,(char **)0L); return 0;} unsigned int _stklen = 6 * 1024; struct sicxh icxh; /**/int main(int argc, char **argv) {icbhe(); _(argc,argv); return 0;} #include "D:\CeW\cobol\p\mx_b1.t" #pragma warn -par static void _(int argc, char **argv) /* toto je preklad PROCEDURE */ { /* konec zdroje .d */ ------------------------------------------------------- 2nd include C (.t) #define MXPE(x,y) return y #pragma warn -par static short _f0002( int argc, char **argv ) { /* 0074 display "Calculator - directions for use:". */ /* DISPLAY */ fprintf(J9,"Calculator - directions for use:\n"); /* . */ /* 0075 display */ /* DISPLAY */ /* 0076 " - input have to be operator and integer (max 3 digits) " */ /* 0077 "without space". */ fprintf(J10," - input have to be operator and integer (max 3 digits) without space\n"); /* . */ /* 0078 display " - input is Enter only: program ends". */ /* DISPLAY */ fprintf(J11," - input is Enter only: program ends\n"); /* . */ /* 0079 display " - valid operators: +, -, *, /". */ /* DISPLAY */ fprintf(J12," - valid operators: +, -, *, /\n"); /* . */ /* 0080 display " ". */ /* DISPLAY */ fprintf(J13," \n"); /* . */ } -------------------------------------------------------------------------- MX COBOL - free compiler - (c) Vlastimil Cevela 2006 --------------------------------------------------------------------------